<?php
    /**
    * Country - Save
    * @author tunv
    * @since July 11, 2012
    * 
    * Change logs
    * 
    */

    if (!defined('EXPONENT')) exit('');

    $cat = null;
    if (isset($_REQUEST['id'])) {
        $cat = $db->selectObject('bannermediamodule_item','id='.intval($_REQUEST['id']));
        if ($cat) {
            $loc = unserialize($cat->location_data);
        }
    } 
    if (exponent_permissions_check(array('administrate','configure'),$loc)) {

        $cat = bannermedia::bannermedia_update($_POST,$cat);
        $cat->location_data = serialize($loc);
        //Cho nay de insert field rank
        $cat->rank = $db->max('bannermediamodule_item', 'rank', 'location_data', "location_data='".serialize($loc)."'");
        if ($cat->rank == null) {
            $cat->rank = 0;
        } else {
            $cat->rank += 1;
        }
        if (isset($cat->id)) {
            $db->updateObject($cat,'bannermediamodule_item');
        } else {
            $db->insertObject($cat,'bannermediamodule_item');
        }        
        exponent_flow_redirect();
    } else {
        echo SITE_404_HTML;
    }

?>